package cn.topevery.garden.dal.dao.impl;

import cn.topevery.garden.dal.dao.PlanFileDao;
import cn.topevery.garden.entity.po.PlanFile;
import cn.topevery.garden.entity.query.PlanFileQuery;
import cn.topevery.garden.entity.vo.PlanFileVO;
import cn.topevery.garden.framework.base.BaseDaoImpl;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.db.entity.SqlQueryMate;
import hw.topevery.framework.db.enums.ScriptConditionEnum;
import hw.topevery.framework.entity.DbCsp;
import hw.topevery.framework.entity.KeyValue;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 绿地/行道树/古树名木  附件表
 *
 * @author code-generate
 * @date 2022-01-05
 */
@Repository
public class PlanFileDaoImpl extends BaseDaoImpl<PlanFile> implements PlanFileDao {
    @Override
    public <P extends DbCsp> List<PlanFile> getSearch(P para) {
        return null;
    }

    

    @Override
    public DataPager<PlanFileVO> listPage(PlanFileQuery query) {
        String table = "t_plan_file tpf";

        String columns = "tpf.*";

        int pageIndex = query.pageIndex - 1;
        int pageSize = query.pageSize;

        SqlQueryMate sqlQueryMate = new SqlQueryMate(table).setColumns(columns).setOrderBy("tpf.c_id desc");
        sqlQueryMate
                .where(true, "tpf.c_db_status", ScriptConditionEnum.Eq, 0)
        ;

        return getDataPager(sqlQueryMate, pageSize, pageIndex, PlanFileVO.class);
    }

    @Override
    public PlanFile getEntityByColumn(String key,String value){
        KeyValue<String> map=new KeyValue<>();
        map.key=key;
        map.value=value;
        return getEntityByColumnEqValue(map);
    }

    @Override
    public List<PlanFile> list(String planId) {
        SqlQueryMate sqlQueryMate = new SqlQueryMate("t_plan_file tpf").setColumns("tpf.*");
        sqlQueryMate.where(true, "tpf.c_db_status", ScriptConditionEnum.Eq, 0)
                .where(StringUtils.isNotEmpty(planId), "c_plan_id", ScriptConditionEnum.Eq, planId);
        return selectList(sqlQueryMate, PlanFile.class);
    }

    @Override
    public List<PlanFile> list(Integer planIntId) {
        SqlQueryMate sqlQueryMate = new SqlQueryMate("t_plan_file tpf").setColumns("tpf.*");
        sqlQueryMate.where(true, "tpf.c_db_status", ScriptConditionEnum.Eq, 0)
                .where(planIntId != null, "c_plan_int_id", ScriptConditionEnum.Eq, planIntId);
        return selectList(sqlQueryMate, PlanFile.class);
    }
}
